package com.tjbklx1.pattern2.chap32.c03_chain;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Client {
	public static void main(String[] args) throws Exception {
		// 上海域名服务器
		DnsServer sh = new SHDnsServer();
		// 中国顶级域名服务器
		DnsServer china = new ChinaTopDnsServer();
		// 全球顶级域名服务器
		DnsServer top = new TopDnsServer();
		// 定义查询路径
		china.setUpperServer(top);
		sh.setUpperServer(china);
		// 解析域名
		System.out.println("=====域名解析模拟器=====");
		while (true) {
			System.out.print("\n请输入域名(输入N退出):");
			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			try {
				String domain = in.readLine();
				if (domain.equalsIgnoreCase("n")) {
					System.out.println("quit!!!");
					return;
				}
				Recorder recorder = sh.resolve(domain);
				System.out.println("----DNS服务器解析结果----");
				System.out.println(recorder);
				
			} catch (IOException ioe) {
				System.err.println("IO error trying to read your answer");
			}
		}
	}
}